package com.dinadi.yidi.adapter;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.AddressManagementEntity;
import com.dinadi.yidi.bean.CategoryRequestEntity;

import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/11/23
 * Time: 11:22
 */

public class ChoiceAreaAdapter extends BaseAdapter {

    private Activity mContext;

    private List<AddressManagementEntity> mDatas;


    public ChoiceAreaAdapter(Activity context, List<AddressManagementEntity> mList) {
        this.mContext = context;
        this.mDatas = mList;
    }

    public void addAllData(List<AddressManagementEntity> dataList) {
        this.mDatas.addAll(dataList);
        notifyDataSetChanged();
    }

    public void clearData(List<AddressManagementEntity> dataList) {
        this.mDatas = dataList;
        this.mDatas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_choice_area, null); /**这个是评论的item列表*/
            viewHolder = new ViewHolder();
            viewHolder.tv_area = (TextView) convertView.findViewById(R.id.tv_area);
            viewHolder.select_area = (RelativeLayout) convertView.findViewById(R.id.select_area);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_area.setText(mDatas.get(position).getName());
        viewHolder.select_area.setOnClickListener(new ChoiceAreaAdapterOnClickListener(position));

        return convertView;
    }


    class ViewHolder {
        TextView tv_area;
        RelativeLayout select_area;
    }

    private class ChoiceAreaAdapterOnClickListener implements View.OnClickListener {
        int position;

        public ChoiceAreaAdapterOnClickListener(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.select_area:

                    /**在这里写个接口，*/
                    onClickListenerCallBack.onClickType(position, mDatas);

                    break;

            }
        }
    }

    public interface OnClickListenerCallBack {
        void onClickType(int position, List<AddressManagementEntity> stringList);

    }

    public OnClickListenerCallBack onClickListenerCallBack;

    public void setOnClickListenerCallBack(OnClickListenerCallBack onClickListenerCallBack) {
        this.onClickListenerCallBack = onClickListenerCallBack;
    }


}

